package com.example.zqm.git72.Adapter;

import android.content.Context;
import android.content.Intent;
import android.support.v7.widget.RecyclerView;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ImageView;
import android.widget.TextView;

import com.example.zqm.git72.Activity.ClubDetailActivity;
import com.example.zqm.git72.JavaBean.Club;
import com.example.zqm.git72.JavaBean.ClubCourse;
import com.example.zqm.git72.JavaBean.ClubMap;
import com.example.zqm.git72.R;
import com.squareup.picasso.Picasso;

import java.util.List;

//import com.example.zqm.git72.Activity.FoodActivity;

/**
 * Created by Administrator on 2017/3/6 0006.
 */

public class ClubCourseListAdapter extends RecyclerView.Adapter<RecyclerView.ViewHolder>{

    private Context mContext;
    private List<ClubMap> mDataList;
    private LayoutInflater mLayoutInflater;

    private ClubMap clubMap;
    //构造方法
    public ClubCourseListAdapter(Context mContext, List<ClubMap> mDataList) {
        this.mContext = mContext;
        this.mDataList = mDataList;

        mLayoutInflater = LayoutInflater.from(mContext);
        if (mDataList.size() >0){

            clubMap = mDataList.get(0);
        }
    }


    @Override
    public RecyclerView.ViewHolder onCreateViewHolder(ViewGroup parent, int viewType) {
        View v = mLayoutInflater.from(parent.getContext()).inflate(R.layout.cardview_clubcourse,parent,false);
        return new ViewHolder(v);
    }

    @Override
    public void onBindViewHolder(RecyclerView.ViewHolder holder, int position) {
        //把viewhoder数据映射到

        if (null == clubMap)
            return;
        ViewHolder viewHolder = (ViewHolder) holder;
        if (clubMap.getClubcourse().size() > 0){

            viewHolder.course_name.setText("课程名："+clubMap.getClubcourse().get(position).getCourse_name());
            viewHolder.degree.setText("等级:"+clubMap.getClubcourse().get(position).getDegree());
            if(clubMap.getClubcourse().get(position).getThumb().equals("")){
                Picasso.with(mContext).load("https://b-ssl.duitang.com/uploads/item/201409/03/20140903102455_SNNnA.png"
                )
                        .resize(50,50).into(viewHolder.course_thumb);
            }else{
                String picUrl = "http://172.24.10.175/workout/Uploads/" + clubMap.getClubcourse().get(position).getThumb();

                Picasso.with(mContext).load(picUrl.toString())
                        .resize(50,50).into(viewHolder.course_thumb);
            }
            //Context上下文在很多Android Api中都是必须的,图片网络加载地址,想进行图片展示的ImageView
            viewHolder.course_price.setText("￥"+clubMap.getClubcourse().get(position).getCourse_price());

            //iewHolder.news_keywords.setText(entity.getKeywords());
            //viewHolder.club_thumb.setImageResource(Integer.parseInt(entity.getThumb()));
            //viewHolder.news_star.setRating(Float.valueOf(entity.getLevel()));

        }

    }

    @Override
    public int getItemCount() {
        return clubMap.getClubcourse().size();
    }


    public class ViewHolder extends RecyclerView.ViewHolder{
        ImageView course_thumb;
        TextView course_name,degree,course_price;
        //RatingBar news_star;
        //构造方法
        public ViewHolder(View itemView) {
            super(itemView);
            course_name = (TextView) itemView.findViewById(R.id.course_name);
            course_thumb = (ImageView) itemView.findViewById(R.id.course_thumb);
            degree=(TextView) itemView.findViewById(R.id.degree);
           course_price = (TextView) itemView.findViewById(R.id.course_price);
            //news_star =(RatingBar) itemView.findViewById(R.id. news_star);

        }
    }

}
